<div data-ng-controller="contractBalanceCtrl">
    <div class="table-header clearfix ng-scope">
        <span class="fl lh30 f14">{{contractBaseInfo.contract_code}}</span>
    </div>
    <form name="balanceEditForm" class="form-horizontal" novalidate>
        <div class="form-group mt10" ng-if="[3,4].indexOf(contractTypeCode)==-1">
            <span for="inputtext3" class="col-sm-3 control-label">签约金额</span>
            <div class="col-sm-5">
                <input type="number" name="sign_amount" data-ng-disabled="true" number required min="0" ng-model="contractBaseInfo.sign_amount"
                       class="form-control align-r" id="inputtext1" placeholder="签约金额">
            </div>

            <span for="inputtext3" class="col-sm-3 control-label">应结算金额</span>
            <div class="col-sm-5">
                <input type="number" name="balance_should_amount" number required min="0" ng-model="contractBaseInfo.balance_should_amount"
                       class="form-control align-r" id="inputtext2" placeholder="应结算金额" data-ng-disabled="!([1,2,5,7].indexOf(contractTypeCode)>=0)">
            </div>

            <div ng-if="contractTypeCode == 2">
                <span for="inputtext3" class="col-sm-3 control-label">已结算金额</span>
                <div class="col-sm-5">
                    <input type="number" data-ng-model="contractBaseInfo.balance_amount" data-ng-disabled="true" number min="0"
                           class="form-control align-r" id="inputtext3" placeholder="已结算金额">
                </div>
            </div>
            <div ng-if="[2,7].indexOf(contractTypeCode)==-1">
                <span for="inputtext3" class="col-sm-3 control-label">已结算金额</span>
                <div class="col-sm-5">
                    <input type="number" id="balance_amount" name="balance_amount" data-ng-disabled="true" number required min="0" value="{{shipments|sumAmount}}"
                           class="form-control align-r" id="inputtext3" placeholder="已结算金额">
                </div>
            </div>
            <div ng-if="[7].indexOf(contractTypeCode)>=0">
                <span class="col-sm-3 control-label">已返款金额</span>
                <div class="col-sm-5">
                    <input type="number" class="form-control align-r"
                           placeholder="返款金额" id="back_amount"
                           required min="0" number name="back_amount"
                           ng-model="back_amount"
                           >
                </div>
            </div>
        </div>
        <div ng-if="[5].indexOf(contractTypeCode)>=0 || ([1,2,5].indexOf(contractTypeCode)>=0 && (contractBaseInfo.contract_property_id=='c33eda1c-54d8-11e7-9f96-000c29310f8b' || contractBaseInfo.contract_property_id=='c3402517-54d8-11e7-9f96-000c29310f8b'))">
            <div class="form-group mt10">
                <span class="col-sm-3 control-label">返款金额</span>
                <div class="col-sm-5">
                    <input type="number" class="form-control align-r"
                           placeholder="返款金额" id="back_amount"
                           required min="0" number name="back_amount"
                           data-ng-disabled="contractTypeCode==7"
                           value="{{back_amount|backAmount:contractBaseInfo.sign_amount:contractBaseInfo.balance_should_amount}}">
                </div>

                <span class="col-sm-3 control-label">返款时间</span>
                <div class="col-sm-5">
                    <input type="text" class="input_date fl form-control" style="width:100%"
                           ui-date format="yyyy-MM-dd" name="back_date" ng-model="contractBaseInfo.back_date"
                           placeholder="返款时间"
                    >
                </div>

                <span class="col-sm-3 control-label">是否收票</span>
                <div class="col-sm-5">
                    <input id="istatus" select2 ng-model="contractBaseInfo.back_receive_status" select2-model="ddl2BackReceiveStatus"
                           config="ddlConfigBackReceiveStatus" class="form-control" type="text" placeholder="是否收票"/>
                </div>
            </div>

            <div class="form-group mt10">
                <span class="col-sm-3 control-label">发票代码</span>
                <div class="col-sm-5">
                    <input type="text" class="form-control"
                           placeholder="发票代码" id="back_invoice_code"
                           data-ng-model="contractBaseInfo.back_invoice_code">
                </div>
            </div>
        </div>

        <hr ng-if="[7].indexOf(contractTypeCode)>=0">

        <div ng-if="[7].indexOf(contractTypeCode)>=0">
            <div class="mt20 clearfix ng-scope ml25">
                <span  class="fl lh30 f14 c-orange">返款信息</span>
                <div class="fr btn-group">
                    <button href="javascript:;" class="btn"
                            ui-dialog="新增"
                            ui-dialog-data="{}"
                            ui-dialog-show="backAmountService.onBackEditShow($dialog,$dialogScope,'')"
                            ui-dialog-ok="backAmountService.editBackSave($dialog,$dialogScope,contractBaseInfo.contract_id,getContract)"
                            ui-dialog-cache="false"
                            ui-dialog-url="/contract/editinc/balance-inc-edit-back.html"
                            ng-if="contractBaseInfo.is_cancelled == 0"
                    >新增
                    </button>
                </div>
            </div>
            <div id="grid5" class="table-wrap mt10 ml25" style="min-height: 150px;">
                <table width="100%">
                    <thead>
                    <tr>
                        <th width="40">序号</th>
                        <th width="200">返款区域</th>
                        <th width="200">返款金额</th>
                        <th width="220">返款时间</th>
                        <th width="200">是否收票</th>
                        <th width="200">发票代码</th>
                        <th width="50">备注</th>
                        <th width="80">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr ng-repeat="record in backamountlist">
                        <td height="40"><p ng-bind="$index + 1"></p></td>
                        <td class="lh14">
                            <span ng-bind="record.area_name"/>
                        </td>
                        <td class="lh14">
                            <span ng-bind="record.back_amount"/>
                        </td>
                        <td class="lh14">
                            <p>{{record.back_date|strdate:'yyyy-MM-dd'}}</p>
                        </td>
                        <td class="lh14">
                            <span ng-bind="record.is_received_invoce_code"/>
                        </td>
                        <td class="lh14">
                            <span ng-bind="record.invoice_code"/>
                        </td>
                        <td class="lh14">
                            <a data-ng-click="showmsg(record.remark)">查看</a>
                        </td>
                        <td class="lh14">
                            <div row-toolbar min-buttons-show="2">
                                <a href="javascript:;"
                                   ui-dialog="修改"
                                   ui-dialog-data="{}"
                                   ui-dialog-show="backAmountService.onBackEditShow($dialog,$dialogScope,record)"
                                   ui-dialog-ok="backAmountService.editBackSave($dialog,$dialogScope,contractBaseInfo.contract_id,getContract)"
                                   ui-dialog-cache="false"
                                   ui-dialog-url="/contract/editinc/balance-inc-edit-back.html"
                                >修改
                                </a>
                                <a href="javascript:void(0)" class="clearfix"
                                   title="删除"
                                   ng-click="backAmountService.deleteBack(record,getContract)">删除</a>
                            </div>
                        </td>
                    </tr>
                    </tbody>
                </table>
                <div class="no-data-2" ng-if="!backamountlist || backamountlist.length === 0"><span>暂无数据</span></div>
            </div>
        </div>

        <hr ng-if="[1,5].indexOf(contractTypeCode)>=0">

        <div ng-if="[1,5].indexOf(contractTypeCode)>=0">
            <div class="mt20 clearfix ng-scope ml25">
                <span  class="fl lh30 f14 c-orange">出库信息</span>
            </div>
            <div id="grid" class="table-wrap mt10 ml25" style="min-height: 150px;">
                <table width="100%">
                    <thead>
                    <tr>
                        <th width="40">序号</th>
                        <th width="220">出库日期</th>
                        <th width="200">出库数量</th>
                        <th width="200">出库金额</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr ng-repeat="record in shipments">
                        <td height="40"><p ng-bind="$index + 1"></p></td>
                        <td class="lh14">
                            <span ng-bind="record.shipment_time | strdate:'yyyy-MM-dd'"/>
                        </td>
                        <td class="lh14">
                            <span ng-bind="record.shipment_numberic"/>
                        </td>
                        <td class="lh14">
                            <p ng-bind="record.amount"></p>
                        </td>
                    </tr>
                    </tbody>
                </table>
                <div class="no-data-2" ng-if="!shipments || shipments.length === 0"><span>暂无数据</span></div>
            </div>
            <span  class="ml25">出库金额合计:{{shipments|sumAmount}}元</span>
        </div>
        <hr ng-if="[1,5].indexOf(contractTypeCode)>=0">
        <div ng-if="[1,5].indexOf(contractTypeCode)>=0">
            <div class="mt20 clearfix ng-scope ml25">
                <span  class="fl lh30 f14 c-orange">结算信息</span>
                <div class="fr btn-group" ng-if="[1].indexOf(contractTypeCode)>=0 && canAddNewBalance == 1">
                    <button type="button" class="btn btn-yellow" ng-click="newPayover()">新增结算</button>
                </div>
            </div>
            <div id="grid2" class="table-wrap mt10 ml25" style="min-height: 150px;">
                <table width="100%">
                    <thead>
                    <tr>
                        <th width="40">序号</th>
                        <th width="200">出库单号</th>
                        <th width="200">应用名称</th>
                        <th width="160">开通时间</th>
                        <th width="160">租期(月)</th>
                        <th width="100">授权数量</th>
                        <th width="200">结算类型</th>
                        <th width="100">结算基准单价</th>
                        <th width="100">区域折扣(%)</th>
                        <th width="100">当次优惠折扣(%)</th>
                        <th width="100">当次实际折扣(%)</th>

                        <th width="150">结算比例(%)</th>
                        <th width="150">结算金额</th>
                        <th width="150">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr ng-repeat="record in payovers">
                        <td height="40"><p ng-bind="$index + 1"></p></td>
                        <!--<td class="lh14">
                            <p ng-bind="record.stock_out_code"></p>
                        </td>-->
                        <td>
                            <p ng-if="(record.editMode || 0) == 0" ng-bind="record.stock_out_code"></p>

                            <input type="text" name="stock_out_code" required class="form-control align-r"
                                   ng-if="(record.editMode || 0) != 0"
                                   ng-disabled="record.stock_out_id != '' && record.stock_out_id != null"
                                   ng-model="record.stock_out_code"  min="0"
                                   placeholder="出库单号">
                        </td>
                        <td class="lh14">
                            <p ng-if="(record.editMode || 0) != 1" ng-bind="record.application_name"></p>

                            <div ng-if="(record.editMode || 0) == 1">
                                <input id="application_id" select2 ng-model="record.application_id" select2-model="ddl2ApplicationName"
                                       config="ddlConfigApplicationName" class="form-control" placeholder="应用名称"/>
                            </div>
                        </td>
                        <td class="lh14">
                            <span ng-if="(record.editMode || 0) == 0" ng-bind="record.authorize_time | strdate:'yyyy-MM-dd'"/>

                            <input type="text" name="authorize_time" required class="form-control input-date"
                                   ng-if="(record.editMode || 0) != 0"
                                   ng-model="record.authorize_time" ui-date
                                   format="yyyy-MM-dd" required
                                   style="width: 100%" placeholder="开通时间">
                        </td>
                        <td class="lh14">
                            <span ng-if="(record.editMode || 0) == 0" ng-bind="record.authorize_period"/>
                            <input type="number" name="authorize_period" required class="form-control input-date"
                                   ng-if="(record.editMode || 0) != 0" min="0"
                                   ng-model="record.authorize_period" required
                                   style="width: 100%" placeholder="租期">
                        </td>
                        <td class="lh14">
                            <span ng-if="(record.editMode || 0) == 0" ng-bind="record.authorization_numeric"/>

                            <input type="number" name="authorization_numeric" required class="form-control align-r"
                                   ng-if="(record.editMode || 0) != 0"
                                   ng-model="record.authorization_numeric" min="0"
                                   placeholder="授权数量">
                        </td>
                        <td class="lh14">
                            <p ng-if="(record.editMode || 0) == 0" ng-bind="record.balance_type_name"></p>

                            <div ng-if="(record.editMode || 0) != 0">
                                <input id="balance_type" name="balance_type" select2 ng-model="record.balance_type" select2-model="ddl2BalanceType"
                                       config="ddlConfigBalanceType" class="form-control" placeholder="结算类型"/>
                            </div>
                        </td>

                        <td class="lh14">
                            <p ng-if="(record.editMode || 0) != 1" ng-bind="record.BenchmarkPrice"></p>
                        </td>

                        <td class="lh14">
                            <p ng-if="(record.editMode || 0) != 1" ng-bind="record.Qyzk"></p>
                        </td>

                        <td class="lh14">
                            <p ng-if="(record.editMode || 0) != 1" ng-bind="record.DcYhzk"></p>
                        </td>

                        <td class="lh14">
                            <p ng-if="(record.editMode || 0) != 1" ng-bind="record.DcSjzk"></p>
                        </td>

                        <td class="align-m">
                            <p ng-if="(record.editMode || 0) == 0" ng-bind="record.balance_rate"></p>

                            <input type="number" name="balance_rate" required class="form-control align-r"
                                   ng-if="(record.editMode || 0) != 0"
                                   ng-model="record.balance_rate" number required min="0"
                                   placeholder="结算比例">
                        </td>
                        <td class="align-m">
                            <p ng-if="(record.editMode || 0) == 0" ng-bind="record.balance_amount"></p>

                            <input type="number" name="balance_amount" required class="form-control align-r"
                                   ng-if="(record.editMode || 0) != 0"
                                   ng-model="record.balance_amount" number required min="0"
                                   placeholder="结算金额">
                        </td>
                        <td class="lh14">
                            <a ng-if="(record.editMode || 0)  == 0" href="javascript:void(0)"
                               title="修改信息"
                               ng-click="editPayover(record, $index)">修改</a>

                            <a ng-if="(record.editMode || 0)  != 0" href="javascript:void(0)"
                               title="保存信息"
                               ng-click="savePayover(record)">确定</a>
                            <a ng-if="(record.editMode || 0)  != 0" href="javascript:void(0)"
                               title="取消"
                               ng-click="cancelPayover(record, $index)">取消</a>
                        </td>
                    </tr>
                    </tbody>
                </table>
                <div class="no-data-2" ng-if="!payovers || payovers.length === 0"><span>暂无数据</span></div>
            </div>
            <span  class="ml25">结算金额合计:<span id="sumBalanceAmount">{{payovers|sumBalanceAmount}}</span>元</span><br/>
        </div>

        <div class="form-group mt10" ng-if="[1,2,5].indexOf(contractTypeCode)>=0">
            <span class="col-sm-3 control-label">备注</span>

            <div class="col-sm-21">
                <textarea type="text" ng-model="contractBaseInfo.balance_remark" class="form-control" id="remark"
                          placeholder="备注" rows="4"></textarea>
            </div>
        </div>
        <div class="form-group" ng-if="[1,2,5,7].indexOf(contractTypeCode)>=0">
            <div class="ml35 mt15">
                <button type="submit" ng-click="save()" class="btn btn-default">保存</button>
            </div>
        </div>
    </form>
</div>